package flc.ast.utils;

import android.util.Log;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class NetworkActivitySimulator {
    private static final String TEST_URL = "https://ys-api.mihoyo.com/event/download_porter/link/ys_cn/official/pc_backup307"; // 大文件 URL
    private boolean isRunning = false;
    private Thread simulationThread;

    public void startSimulation() {
        if (isRunning) return;

        isRunning = true;
        simulationThread = new Thread(() -> {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(TEST_URL).build();

            while (isRunning) {
                try {
                    Response response = client.newCall(request).execute();
                    if (response.isSuccessful()) {
                        Log.d("NetworkActivity", "Simulated network activity");
                    }
                    response.close();
                } catch (Exception e) {
                    Log.e("NetworkActivity", "Error simulating network activity", e);
                }
            }
        });

        simulationThread.start();
    }

    public void stopSimulation() {
        isRunning = false;
        if (simulationThread != null) {
            try {
                simulationThread.join();
            } catch (InterruptedException e) {
                Log.e("NetworkActivity", "Error stopping simulation thread", e);
            }
        }
    }
}